package com.handinfo.android.ui.window;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.concurrent.CopyOnWriteArrayList;

import android.graphics.Bitmap;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.graphics.DWGraphics;
import com.handinfo.android.game.Cell;
import com.handinfo.android.game.GameMessage;
import com.handinfo.android.game.item.BaGuaLu;
import com.handinfo.android.game.item.Item;
import com.handinfo.android.game.item.ItemConstants;
import com.handinfo.android.game.item.ItemEquipment;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlTools;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWExternalDraw;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWCheckbox;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWGrid;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWListSubItem;
import com.handinfo.android.uicontrols.controls.DWListbox;
import com.handinfo.android.uicontrols.controls.DWMessageBox;
import com.handinfo.android.uicontrols.controls.DWPopMenu;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

/**
 * 
 * 八卦炉
 * 
 * @author mujianchen
 * 
 */

public class UIBagualu implements IUIWindows
{
	public DWFrame m_bgFrame = null;
	public DWTitle m_bgTitle = null;

	public DWImageBox m_bgImageBox_GB = null;
	public DWImageBox m_bgImageBox_BT = null;

	public DWBackground[] m_bgBackground = new DWBackground[2];//背景集合
	public DWImageBox m_bgImageBox_BeiJing = null;//八卦炉背景

	public Bitmap m_bgBitmap01 = null;
	public Bitmap m_bgBitmap02 = null;
	public Bitmap m_bgBitmap02_ax = null;

	public Bitmap m_bgBitmap03 = null;
	public Bitmap m_bgBitmap03_ax = null;

	public Bitmap m_XuanZe_Bitmap = null;//弹窗长按钮
	public Bitmap m_XuanZe_Bitmap_ax = null;//弹窗长按钮 按下

	public Bitmap m_bgBitmap_BT = null;

	public Bitmap m_bgBitmap_KaiShi01 = null;//开始熔炼图片亮
	public Bitmap m_bgBitmap_KaiShi02 = null;//开始熔炼图片暗
	public Bitmap m_bgBitmap_BaGuaLu = null;//八卦炉背景
	public Bitmap m_bgBitmap_JinZhuang = null;//金装图标
	public Bitmap m_bgBitmap_WenZi = null;//炼化金装成功率:
	public Bitmap m_bgBitmap_Num = null;//数字拼接
	public Bitmap m_bgBitmap_Num_dian = null;//小数点
	public Bitmap m_bgBitmap_Num_baifenhao = null;//百分号

	public DWImageBox m_bgImageBox_JinZhuang = null;//金装图标

	public DWTextbox m_bgTextbox_xiaTiShi = null;//最下边提示文字

	public DWListbox m_bgListbox_ZhuangBei = null;//右侧装备列表

	public DWButton m_bgButton_RongLian = null;//炼成按钮
	public DWButton m_bgButton_XuanZeBuWei = null;//选择部位按钮
	public DWButton m_bgButton_ZengJiaJiLv = null;//增加几率按钮

	public DWPopMenu m_bgPopMenu_XuanZeBuWei = null;//选择部位菜单
	public DWPopMenu m_bgPopMenu_ZengJiaJiLv = null;//增加几率菜单

	public DWTextbox m_bgTextbox_ChengGongLv = null;//成功率

	public Bitmap m_bgBitmap_Grid = null;
	public DWImageBox m_bgImageBox_Grid = null;//显示格子

	public DWTextbox m_bgTextbox_YuanBao = null;//话费元宝数量
	public DWTextbox m_bgTextbox_ShengCheng = null;//生成装备类型提示

	public Cell[] m_equip_list;//操作装备列表
	public CopyOnWriteArrayList<Cell> m_equip_cache_list;//缓存列表
	public DWCheckbox[] m_bgCheckbox_ZhuangBei;//装备选择

	/** 增加几率按钮下标 */
	public int m_JiLv_index = -1;

	public DWImageBox m_bgImageBox_ChengGongLv = null;//炼化金装成功率:

	/** 发送炼制装备类型 */
	public byte m_LianZhi_type = 3;

	/** 装备评分GS总和 */
	public int m_ZhuangBei_GS_num = 0;

	/** 是否可以点击熔炼 */
	public boolean m_RongLian_type = false;

	/** 数字拼接 */
	public DWImageBox[] m_ImageBox_num = new DWImageBox[6];

	/** 没有紫装提示 */
	public DWTextbox m_bgTextbox_TiShi = null;

	public void init()
	{
		m_bgBitmap01 = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");//关闭图片
		m_bgBitmap02 = UIWindows.createImage("/img/newui/anniu_4.gnp");//按钮图片开
		m_bgBitmap02_ax = UIWindows.createImage("/img/newui/anniu_4ax.gnp");//按钮图片开

		m_bgBitmap03 = UIWindows.createImage("/img/newui/anniu_10.gnp");//按钮图片开
		m_bgBitmap03_ax = UIWindows.createImage("/img/newui/anniu_10ax.gnp");//按钮图片开

		m_bgBitmap_Grid = UIWindows.createImage("/img/newui/wupinlan.gnp");//格子图片

		m_XuanZe_Bitmap = UIWindows.createImage("/img/newui/anniu_13.gnp");//长按钮图片
		m_XuanZe_Bitmap_ax = UIWindows.createImage("/img/newui/anniu_13ax.gnp");//长按钮图片 按下

		m_bgBitmap_BT = UIWindows.createImage("/img/newui/bagualu_1.gnp");//标题

		m_bgBitmap_KaiShi01 = UIWindows.createImage("/img/newui/kaishilianhua_1.gnp");//开始熔炼亮
		m_bgBitmap_KaiShi02 = UIWindows.createImage("/img/newui/kaishilianhua_2.gnp");//开始熔炼暗
		m_bgBitmap_BaGuaLu = UIWindows.createImage("/img/newui/bagualudt_1.gnp");//八卦炉背景
		m_bgBitmap_JinZhuang = UIWindows.createImage("/img/newui/jinzhuang_1.gnp");//金装图片
		m_bgBitmap_WenZi = UIWindows.createImage("/img/newui/chenggonglv_1.gnp");//炼化金装成功率:
		m_bgBitmap_Num = UIWindows.createImage("/img/newui/shuzi_4.gnp");//数字拼接
		m_bgBitmap_Num_dian = UIWindows.createImage("/img/newui/xiaoshudian_1.gnp");//小数点
		m_bgBitmap_Num_baifenhao = UIWindows.createImage("/img/newui/baifenhao_1.gnp");//小数点
	}

	public void updata()
	{
		if (m_equip_cache_list == null) {
			m_equip_cache_list = new CopyOnWriteArrayList<Cell>();
		}
		else {
			m_equip_cache_list.clear();
		}
		refreshEquipList();
	}

	public void bagualu()
	{
		if (m_bgFrame != null) {
			DWControlsManager.getInstance().removeControl(m_bgFrame);
		}
		m_bgFrame = new DWFrame(DWFrame.FRAME_TYPE_FULL, true);
		m_bgFrame.setClickClose(false);
		m_bgTitle = new DWTitle(null, m_bgFrame);

		m_bgImageBox_BT = new DWImageBox(m_bgBitmap_BT);
		m_bgImageBox_BT.setNearAnchor(m_bgTitle, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);

		m_bgImageBox_GB = new DWImageBox(m_bgBitmap01);
		m_bgImageBox_GB.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				close((byte) 0);
			}
		});
		m_bgImageBox_GB.setNearAnchor(m_bgTitle, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER);
		m_bgImageBox_GB.setTouchZoomIn(20, 20);

		m_bgBackground[0] = new DWBackground(0, 0, m_bgFrame.getShowWidth() / 8 * 5 + 20,
				m_bgFrame.getShowHeight() - 60);
		m_bgBackground[0].setFill(true);
		m_bgBackground[0].setNearAnchor(m_bgFrame, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 20);

		m_bgBackground[1] = new DWBackground(0, 0, m_bgFrame.getShowWidth() / 8 * 3 - 50,
				m_bgFrame.getShowHeight() - 60);
		m_bgBackground[1].setFill(true);
		m_bgBackground[1].setNearAnchor(m_bgFrame, Tools.RIGHT_TOP, Tools.RIGHT_TOP, -10, 20);

		m_bgImageBox_BeiJing = new DWImageBox(m_bgBitmap_BaGuaLu);
		m_bgImageBox_BeiJing.setNearAnchor(m_bgBackground[0], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);

		m_bgImageBox_ChengGongLv = new DWImageBox(m_bgBitmap_WenZi);//成功率
		m_bgImageBox_ChengGongLv.setNearAnchor(m_bgFrame, Tools.LEFT_TOP, Tools.LEFT_TOP, 40, 50);

		m_ImageBox_num[0] = new DWImageBox(m_bgBitmap_Num_baifenhao.getWidth(), m_bgBitmap_Num_baifenhao.getHeight());
		m_ImageBox_num[1] = new DWImageBox(m_bgBitmap_Num_baifenhao.getWidth(), m_bgBitmap_Num_baifenhao.getHeight());
		m_ImageBox_num[2] = new DWImageBox(m_bgBitmap_Num_dian);
		m_ImageBox_num[3] = new DWImageBox(m_bgBitmap_Num_baifenhao.getWidth(), m_bgBitmap_Num_baifenhao.getHeight());
		m_ImageBox_num[4] = new DWImageBox(m_bgBitmap_Num_baifenhao.getWidth(), m_bgBitmap_Num_baifenhao.getHeight());
		m_ImageBox_num[5] = new DWImageBox(m_bgBitmap_Num_baifenhao);
		m_bgTextbox_ChengGongLv = new DWTextbox(null);//TODO
		getGaiLvNUM();
		m_ImageBox_num[0].setNearAnchor(m_bgImageBox_ChengGongLv, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
		for (int j = 1; j < m_ImageBox_num.length; j++) {
			m_ImageBox_num[j].setNearAnchor(m_ImageBox_num[j - 1], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
		}

		getGaiLvNUM();
		m_bgTextbox_ChengGongLv.setNearAnchor(m_bgBackground[0], Tools.HCENTER_TOP, Tools.HCENTER_TOP, 0, 20);

		m_bgTextbox_xiaTiShi = new DWTextbox("<mark c=FFBB11>八卦炉消耗紫装熔炼高品质金装或金装碎片，失败返回部分精魂</mark>");
		m_bgTextbox_xiaTiShi.setNearAnchor(m_bgFrame, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM, 0, -10);

		m_bgListbox_ZhuangBei = new DWListbox(m_bgBackground[1].getShowWidth() - 20,
				m_bgBackground[1].getShowHeight() - 10);
		m_bgListbox_ZhuangBei.setNearAnchor(m_bgBackground[1], Tools.LEFT_TOP, Tools.LEFT_TOP, 5, 5);
		m_bgListbox_ZhuangBei.setLineSpacing(10);

		m_bgTextbox_TiShi = new DWTextbox("背包中没有可用紫装");
		m_bgTextbox_TiShi.setTouch(false);
		if (m_equip_list != null) {
			m_bgTextbox_TiShi.setShow(false);
		}
		else {
			m_bgTextbox_TiShi.setShow(true);
		}
		m_bgTextbox_TiShi.setNearAnchor(m_bgListbox_ZhuangBei, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);

		m_bgImageBox_Grid = new DWImageBox(m_bgBitmap_Grid);
		m_bgImageBox_Grid.setNearAnchor(m_bgBackground[0], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);

		m_bgImageBox_JinZhuang = new DWImageBox(m_bgBitmap_JinZhuang);
		m_bgImageBox_JinZhuang.setShow(false);
		m_bgImageBox_JinZhuang.setNearAnchor(m_bgImageBox_Grid, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);

		m_bgButton_RongLian = new DWButton(null, m_bgBitmap_KaiShi02);
		m_bgButton_RongLian.setNearAnchor(m_bgImageBox_Grid, Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM, 0, 15);
		m_bgButton_RongLian.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				if (m_equip_list.length > 0) {
					if (m_RongLian_type == true) {
						final DWMessageBox mb = new DWMessageBox("提示", "尝试将紫装炼化为金装，是否确定？炼化花费"
								+ getLevelZongHe(m_jinqian_num) + "金币。");
						mb.addListener(new DWListener() {

							public void OnDoubleClick()
							{

							}

							public void OnClick()
							{
								if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
									if (m_JiLv_index == -1) {
										DWGameManager.getInstance().getSendMessage().sendBaGuaLu(
												BaGuaLu.QUEDINGRONGLIAN,
												m_LianZhi_type, 0, m_equip_cache_list);
									}
									else {
										DWGameManager.getInstance().getSendMessage().sendBaGuaLu(
												BaGuaLu.QUEDINGRONGLIAN,
												m_LianZhi_type, m_bagualu[m_JiLv_index].m_Addchenggong,
												m_equip_cache_list);
									}
									DWControlsManager.getInstance().removeControl(mb);
								}
								else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
									DWControlsManager.getInstance().removeControl(mb);
								}
							}
						});
						DWControlsManager.getInstance().addControl(mb);
					}
				}
				else {
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "熔炼失败，请先加入紫装");
				}
			}
		});

		m_bgButton_XuanZeBuWei = new DWButton("选择部位", m_bgBitmap03);
		m_bgButton_XuanZeBuWei.setDownImage(m_bgBitmap03_ax);
		m_bgButton_XuanZeBuWei.setNearAnchor(m_bgButton_RongLian, Tools.RIGHT_TOP, Tools.LEFT_BOTTOM, 50, 10);
		m_bgButton_XuanZeBuWei.addListener(m_XuanZeBuWei_lis);

		m_bgButton_ZengJiaJiLv = new DWButton("增加几率", m_bgBitmap03);
		m_bgButton_ZengJiaJiLv.setDownImage(m_bgBitmap03_ax);
		m_bgButton_ZengJiaJiLv.setNearAnchor(m_bgButton_RongLian, Tools.LEFT_TOP, Tools.RIGHT_BOTTOM, -50, 10);
		m_bgButton_ZengJiaJiLv.addListener(m_ZengJiaJiLv_lis);

		m_bgTextbox_YuanBao = new DWTextbox(null);
		m_bgTextbox_YuanBao.setNearAnchor(m_bgBackground[0], Tools.LEFT_BOTTOM, Tools.LEFT_BOTTOM, 60, -40);

		m_bgTextbox_ShengCheng = new DWTextbox(null);
		m_bgTextbox_ShengCheng.setNearAnchor(m_bgBackground[0], Tools.LEFT_BOTTOM, Tools.RIGHT_BOTTOM, -160, -40);

		for (int i = 0; i < m_bgBackground.length; i++) {
			m_bgFrame.addControl(m_bgBackground[i]);
		}
		m_bgFrame.addControl(m_bgImageBox_BeiJing);
		m_bgFrame.addControl(m_bgImageBox_ChengGongLv);
		m_bgFrame.addControl(m_bgTitle);
		m_bgFrame.addControl(m_bgImageBox_BT);
		m_bgFrame.addControl(m_bgImageBox_GB);
		for (int i = 0; i < m_ImageBox_num.length; i++) {
			m_bgFrame.addControl(m_ImageBox_num[i]);
		}
		//////摆放控件//////
//		m_bgFrame.addControl(m_bgTextbox_ChengGongLv);
		m_bgFrame.addControl(m_bgTextbox_YuanBao);
		m_bgFrame.addControl(m_bgTextbox_ShengCheng);
		m_bgFrame.addControl(m_bgImageBox_Grid);
		m_bgFrame.addControl(m_bgImageBox_JinZhuang);
		m_bgFrame.addControl(m_bgButton_RongLian);
		m_bgFrame.addControl(m_bgButton_XuanZeBuWei);
		m_bgFrame.addControl(m_bgButton_ZengJiaJiLv);
		m_bgFrame.addControl(m_bgTextbox_xiaTiShi);
		m_bgFrame.addControl(m_bgListbox_ZhuangBei);
		m_bgFrame.addControl(m_bgTextbox_TiShi);
		DWControlsManager.getInstance().addControl(m_bgFrame);
	}

	/**
	 * 概率值百分比计算、绘制
	 */
	public void getGaiLvNUM()
	{
		recvGaiLv();
		m_bgTextbox_ChengGongLv.setText("当前成功率" + getGaiLv(m_ZhuangBei_GS_num * 100 / m_base_num, m_JiLv_num) + "%");
	}

	/**
	 * 装备列表
	 */
	public void listbox_ZhuangBei()
	{
		if (m_bgListbox_ZhuangBei != null) {
			m_bgListbox_ZhuangBei.removeAllSubItem();
			if (m_equip_list != null) {
				DWListSubItem[] m_bgLSItem = new DWListSubItem[m_equip_list.length];
				DWTextbox[] m_bgTextbox = new DWTextbox[m_equip_list.length];
				DWTextbox[] m_bgTextbox_gs = new DWTextbox[m_equip_list.length];
				m_bgCheckbox_ZhuangBei = new DWCheckbox[m_equip_list.length];
				for (int j = 0; j < m_equip_list.length; j++) {
					m_bgLSItem[j] = new DWListSubItem();
					m_bgLSItem[j].setAutoWideHigh(false);
					m_bgLSItem[j].setShowWideHighUn(m_bgListbox_ZhuangBei.getShowWidth(), 40);
					m_bgCheckbox_ZhuangBei[j] = new DWCheckbox();
					m_bgCheckbox_ZhuangBei[j].setNearAnchor(m_bgLSItem[j],
							Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
					m_bgCheckbox_ZhuangBei[j].setChecked(m_equip_list[j].m_selected);
					m_bgCheckbox_ZhuangBei[j].addListener(new DWListener() {

						public void OnDoubleClick()
						{

						}

						public void OnClick()
						{
							final int index = m_bgListbox_ZhuangBei.getTouchIndex();
							Cell cell = (Cell) m_equip_list[index];
							if (cell != null) {
								cell.m_selected = m_bgCheckbox_ZhuangBei[index].getChecked();
								addCache(cell, cell.m_selected);
							}
						}
					});

					m_bgTextbox[j] = new DWTextbox("<mark c=" + UIBag.getNameColor(m_equip_list[j].m_item.m_quality)
							+ ">" + m_equip_list[j].m_item.m_name + "</mark>");
					m_bgTextbox[j].setNearAnchor(m_bgCheckbox_ZhuangBei[j], Tools.LEFT_TOP, Tools.LEFT_TOP, 60, 0);

					Cell cell = (Cell) m_equip_list[j];
					ItemEquipment item = (ItemEquipment) cell.m_item;

					m_bgTextbox_gs[j] = new DWTextbox("" + item.m_gs);
					m_bgTextbox_gs[j].setNearAnchor(m_bgTextbox[j], Tools.LEFT_TOP, Tools.LEFT_TOP, 100, 0);

					m_bgLSItem[j].addControls(m_bgCheckbox_ZhuangBei[j]);
					m_bgLSItem[j].addControls(m_bgTextbox[j]);
//					m_bgLSItem[j].addControls(m_bgTextbox_gs[j]);//TODO 正式版记得屏蔽
					m_bgListbox_ZhuangBei.addSubItem(m_bgLSItem[j]);
				}
			}
		}
	}

	/**
	 * 获取当前缓存列表装备的所有GS分
	 * @return
	 */
	public int getGsAllNum(boolean type)
	{
		int gs = 0;
		if (type = true) {
			for (Cell cell : m_equip_cache_list) {
				if (cell != null && cell.m_item != null && cell.m_item instanceof ItemEquipment) {
					ItemEquipment item = (ItemEquipment) cell.m_item;
					gs += item.m_gs;
				}
			}
		}
		else {
			for (Cell cell : m_equip_cache_list) {
				if (cell != null && cell.m_item != null && cell.m_item instanceof ItemEquipment) {
					ItemEquipment item = (ItemEquipment) cell.m_item;
					gs -= item.m_gs;
				}
			}
		}
		if (gs < 0) {
			gs = 0;
		}
		return gs;
	}

	/**
	 * 装备总消耗金钱
	 */
	public int getLevelZongHe(int money)
	{
		int num = 0;
		for (Cell cell : m_equip_cache_list) {
			if (cell != null && cell.m_item != null && cell.m_item instanceof Item) {
				num += cell.m_item.m_minLevelLimit;
			}
		}
		num = num * money;
		return num;
	}

	/**
	 * 添加到缓存列表
	 */
	private void addCache(Cell cell, boolean flag)
	{
		if (cell != null && cell.m_item != null && cell.m_item instanceof ItemEquipment) {
			if (flag) {
				if (!m_equip_cache_list.contains(cell)) {
					if (getGaiLv(m_ZhuangBei_GS_num * 100 / m_base_num, 0) >= 6000) {
						cell.m_selected = false;
						DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
								"炼化值已到达极限，不能再添加装备了");
						m_bgCheckbox_ZhuangBei[m_bgListbox_ZhuangBei.getTouchIndex()].setChecked(false);
					}
					else {
						m_equip_cache_list.add(cell);
						m_ZhuangBei_GS_num = getGsAllNum(true);
					}
				}
			}
			else {
				if (m_equip_cache_list.contains(cell)) {
					m_equip_cache_list.remove(cell);
					m_ZhuangBei_GS_num = getGsAllNum(false);
				}
			}
		}
		if (m_equip_list != null) {
			m_bgTextbox_TiShi.setShow(false);
		}
		else {
			m_bgTextbox_TiShi.setShow(true);
		}
		Tools.debugPrintln("m_equip_cache_list--------------->" + m_equip_cache_list.size());
		ronglian_index(getGaiLv(m_ZhuangBei_GS_num * 100 / m_base_num, m_JiLv_num));
		getGaiLvNUM();
		if (m_equip_cache_list.size() == 0) {
			delCacheList();
		}
		recvGaiLv();
	}

	/**
	 * 清理缓存列表
	 */
	private void delCacheList()
	{
		for (Cell c : m_equip_cache_list) {
			c.m_selected = false;
		}
		m_equip_cache_list.clear();
		m_ZhuangBei_GS_num = 0;
		ronglian_index(m_ZhuangBei_GS_num);
		m_bgTextbox_TiShi.setShow(false);
		getGaiLvNUM();
	}

	/**
	 * @exception 刷新出装备列表
	 * @param TabIndex 标签索引
	 */
	public void refreshEquipList()
	{
		CopyOnWriteArrayList<Cell> array = new CopyOnWriteArrayList<Cell>();
		Cell[] cell = null;
		cell = DWGameManager.getInstance().m_role.getCells(Cell.TYPE_COLUMN_ROLEBAG);
		if (cell != null) {
			for (Cell c : cell) {
				if (c != null && c.m_item != null) {
					if (c.m_item instanceof ItemEquipment
							&& c.m_item.m_type == ItemConstants.道具类型_装备
							&& c.m_item.m_quality >= ItemConstants.稀有度_紫) {
						if (c.m_item.m_subtype == ItemConstants.装备_武器
								|| c.m_item.m_subtype == ItemConstants.装备_头部
								|| c.m_item.m_subtype == ItemConstants.装备_上衣
								|| c.m_item.m_subtype == ItemConstants.装备_腰带
								|| c.m_item.m_subtype == ItemConstants.装备_裤子
								|| c.m_item.m_subtype == ItemConstants.装备_鞋子
								|| c.m_item.m_subtype == ItemConstants.装备_称号
								|| c.m_item.m_subtype == ItemConstants.装备_项链
								|| c.m_item.m_subtype == ItemConstants.装备_手腕
								|| c.m_item.m_subtype == ItemConstants.装备_戒指
								|| c.m_item.m_subtype == ItemConstants.装备_法宝
								|| c.m_item.m_subtype == ItemConstants.装备_护符) {
							Tools.debugPrintln("可炼魂装备------------>" + c.m_item.m_name);
							if (((ItemEquipment) c.m_item).m_equipGemsSize == 0) {
								array.add(c);
							}
							else if (((ItemEquipment) c.m_item).m_equipGemsSize == 4)
							{
								if (((ItemEquipment) c.m_item).m_hasGem[0] == ItemConstants.含有宝石_否
										&& ((ItemEquipment) c.m_item).m_hasGem[1] == ItemConstants.含有宝石_否
										&& ((ItemEquipment) c.m_item).m_hasGem[2] == ItemConstants.含有宝石_否
										&& ((ItemEquipment) c.m_item).m_hasGem[3] == ItemConstants.含有宝石_否) {
									array.add(c);
								}
							}
						}
					}
				}
			}
		}
		m_equip_list = null;
		int size = array.size();
		if (size > 0) {
			m_equip_list = new Cell[size];
			for (int i = 0; i < size; i++) {
				m_equip_list[i] = array.get(i);
			}
		}
		array = null;
	}

	/**
	 * 概率计算
	 */
	public int m_gainlv_quanju = 0;

	public int getGaiLv(int num, int yuanbao)
	{
		m_gainlv_quanju = yuanbao;
		if (num >= 6000) {
			num = 6000;
		}
		num = num + (yuanbao * 100);
		return num;
	}

	public int m_old_yuanbao_num = 0;//最终的装备选择消耗

	/**
	 * 刷新消费元宝数
	 */
	public void huafei_yuanbao()
	{
		m_YuanBao_ZongHe = m_old_yuanbao_num + m_JiLv_yuanbao;
	}

	/**
	 * 是否可以熔炼判断
	 */
	public void ronglian_index(int num)
	{
		if (num > 0) {
			m_bgButton_RongLian.setBackground(m_bgBitmap_KaiShi01, true);
			m_RongLian_type = true;
			m_bgImageBox_JinZhuang.setShow(true);
		}
		else {
			m_bgButton_RongLian.setBackground(m_bgBitmap_KaiShi02, true);
			m_RongLian_type = false;
			m_bgImageBox_JinZhuang.setShow(false);
		}
	}

	/**
	 * 选择装备 监听
	 */
	public DWFrame m_XuanZe_Frame = null;
	public DWTitle m_XuanZe_Title = null;
	public DWImageBox m_XuanZe_ImageBox_gb = null;
	public DWButton m_XuanZe_Button01 = null;
	public DWButton m_XuanZe_Button02 = null;
	public DWButton m_XuanZe_Button03 = null;
	public DWButton m_XuanZe_Button_gb = null;
	public DWBackground m_XuanZe_Background = null;

	public DWTextbox m_XuanZe_Textbox_TiShi = null;

	public DWListener m_XuanZeBuWei_lis = new DWListener() {//TODO

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			m_XuanZe_Frame = new DWFrame(DWGameManager.Screen_Width / 2, DWGameManager.Screen_Height / 2 + 70);
			m_XuanZe_Title = new DWTitle("选择装备", m_XuanZe_Frame);

			m_XuanZe_ImageBox_gb = new DWImageBox(m_bgBitmap01);
			m_XuanZe_ImageBox_gb.addListener(new DWListener() {

				public void OnDoubleClick()
				{

				}

				public void OnClick()
				{
					DWControlsManager.getInstance().removeControl(m_XuanZe_Frame);
				}
			});
			m_XuanZe_ImageBox_gb.setNearAnchor(m_XuanZe_Title, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER);
			m_XuanZe_ImageBox_gb.setTouchZoomIn(20, 20);

			m_XuanZe_Background = new DWBackground(m_XuanZe_Frame.getShowWidth() - 20,
					m_XuanZe_Frame.getShowHeight() - 30);
			m_XuanZe_Background.setFill(true);
			m_XuanZe_Background.setNearAnchor(m_XuanZe_Frame, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM, 0, -10);

			m_XuanZe_Button01 = new DWButton("炼制武器", m_bgBitmap02);
			m_XuanZe_Button02 = new DWButton("炼制防具", m_bgBitmap02);
			m_XuanZe_Button03 = new DWButton("炼制饰品", m_bgBitmap02);

			m_XuanZe_Button01.setDownImage(m_bgBitmap02_ax);
			m_XuanZe_Button02.setDownImage(m_bgBitmap02_ax);
			m_XuanZe_Button03.setDownImage(m_bgBitmap02_ax);

			m_XuanZe_Button01.setNearAnchor(m_XuanZe_Frame, Tools.HCENTER_TOP, Tools.HCENTER_TOP, 0, 80);
			m_XuanZe_Button02.setNearAnchor(m_XuanZe_Button01, Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM, 0, 20);
			m_XuanZe_Button03.setNearAnchor(m_XuanZe_Button02, Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM, 0, 20);

			m_XuanZe_Button01.addListener(new DWListener() {

				public void OnDoubleClick()
				{

				}

				public void OnClick()
				{
					m_LianZhi_type = 0;
					m_bgTextbox_ShengCheng.setText("生成：武器");
					m_old_yuanbao_num = m_yuanbao_num;
					huafei_yuanbao();
					m_bgTextbox_YuanBao.setText("花费：" + m_YuanBao_ZongHe + "元宝");
//					getGaiLvNUM();
					DWControlsManager.getInstance().removeControl(m_XuanZe_Frame);
				}
			});

			m_XuanZe_Button02.addListener(new DWListener() {

				public void OnDoubleClick()
				{

				}

				public void OnClick()
				{
					m_LianZhi_type = 1;
					m_bgTextbox_ShengCheng.setText("生成：防具");
					m_old_yuanbao_num = m_yuanbao_num;
					huafei_yuanbao();
					m_bgTextbox_YuanBao.setText("花费：" + m_YuanBao_ZongHe + "元宝");
//					getGaiLvNUM();
					DWControlsManager.getInstance().removeControl(m_XuanZe_Frame);
				}
			});

			m_XuanZe_Button03.addListener(new DWListener() {

				public void OnDoubleClick()
				{

				}

				public void OnClick()
				{
					m_LianZhi_type = 2;
					m_bgTextbox_ShengCheng.setText("生成：饰品");
					m_old_yuanbao_num = m_yuanbao_num;
					huafei_yuanbao();
					m_bgTextbox_YuanBao.setText("花费：" + m_YuanBao_ZongHe + "元宝");
//					getGaiLvNUM();
					DWControlsManager.getInstance().removeControl(m_XuanZe_Frame);
				}
			});

			m_XuanZe_Button_gb = new DWButton("取消", m_bgBitmap02);
			m_XuanZe_Button_gb.setDownImage(m_bgBitmap02_ax);
			m_XuanZe_Button_gb.setNearAnchor(m_XuanZe_Frame, Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, -20, -20);
			m_XuanZe_Button_gb.addListener(new DWListener() {

				public void OnDoubleClick()
				{

				}

				public void OnClick()
				{
					DWControlsManager.getInstance().removeControl(m_XuanZe_Frame);
				}
			});

			m_XuanZe_Textbox_TiShi = new DWTextbox("消耗" + m_yuanbao_num + "元宝设定炼制宝物的种类吗？");
			m_XuanZe_Textbox_TiShi.setNearAnchor(m_XuanZe_Title, Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM, 0, 10);

			m_XuanZe_Frame.addControl(m_XuanZe_Background);
			m_XuanZe_Frame.addControl(m_XuanZe_Title);
			m_XuanZe_Frame.addControl(m_XuanZe_ImageBox_gb);
			m_XuanZe_Frame.addControl(m_XuanZe_Textbox_TiShi);
			m_XuanZe_Frame.addControl(m_XuanZe_Button01);
			m_XuanZe_Frame.addControl(m_XuanZe_Button02);
			m_XuanZe_Frame.addControl(m_XuanZe_Button03);
//			m_XuanZe_Frame.addControl(m_XuanZe_Button_gb);
			DWControlsManager.getInstance().addControl(m_XuanZe_Frame);
		}
	};

	/**
	 * 增加几率 监听
	 */
	public DWFrame m_ZengJia_Frame = null;
	public DWTitle m_ZengJia_Title = null;
	public DWImageBox m_ZengJia_ImageBox_gb = null;
	public DWButton[] m_ZengJia_Button;
	public DWButton m_ZengJia_Button_gb = null;
	public DWBackground m_ZengJia_Background = null;

	public DWTextbox m_ZengJia_Textbox_TiShi = null;

	public DWListener m_ZengJiaJiLv_lis = new DWListener() {//TODO

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			m_ZengJia_Frame = new DWFrame(DWGameManager.Screen_Width / 2, 110 + m_size
					* (m_XuanZe_Bitmap.getHeight() + 20));
			m_ZengJia_Title = new DWTitle("增加几率", m_ZengJia_Frame);
			m_ZengJia_Button = new DWButton[m_size];

			m_ZengJia_ImageBox_gb = new DWImageBox(m_bgBitmap01);
			m_ZengJia_ImageBox_gb.addListener(new DWListener() {

				public void OnDoubleClick()
				{

				}

				public void OnClick()
				{
					DWControlsManager.getInstance().removeControl(m_ZengJia_Frame);
				}
			});
			m_ZengJia_ImageBox_gb.setNearAnchor(m_ZengJia_Title, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER);
			m_ZengJia_ImageBox_gb.setTouchZoomIn(20, 20);

			m_ZengJia_Background = new DWBackground(m_ZengJia_Frame.getShowWidth() - 20,
					m_ZengJia_Frame.getShowHeight() - 30);
			m_ZengJia_Background.setFill(true);
			m_ZengJia_Background.setNearAnchor(m_ZengJia_Frame, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM, 0, -10);

			for (int i = 0; i < m_size; i++) {
				final int JiLv_index = i;
				m_ZengJia_Button[JiLv_index] = new DWButton("提高成功几率"
						+ m_bagualu[JiLv_index].m_Addchenggong
						+ "%          "
						+ m_bagualu[JiLv_index].m_Addchenggongyb
						+ "元宝", m_XuanZe_Bitmap);
				m_ZengJia_Button[JiLv_index].setDownImage(m_XuanZe_Bitmap_ax);
				m_ZengJia_Button[JiLv_index].setNearAnchor(m_ZengJia_Frame, Tools.HCENTER_TOP, Tools.HCENTER_TOP, 0,
						80 + JiLv_index * (m_ZengJia_Button[JiLv_index].getShowHeight() + 20));
				m_ZengJia_Button[JiLv_index].addListener(new DWListener() {

					public void OnDoubleClick()
					{

					}

					public void OnClick()
					{
						m_JiLv_index = JiLv_index;
						int JiLv_num = m_bagualu[m_JiLv_index].m_Addchenggong;
						m_JiLv_num = JiLv_num;
						int JiLv_yuanbao = m_bagualu[m_JiLv_index].m_Addchenggongyb;
						m_JiLv_yuanbao = JiLv_yuanbao;
						huafei_yuanbao();
						m_bgTextbox_YuanBao.setText("花费：" + m_YuanBao_ZongHe + "元宝");
						if (m_equip_cache_list.size() == 0) {
							ronglian_index(0);
						}
						else {
							ronglian_index(1);
						}
						getGaiLvNUM();
						recvGaiLv();
						DWControlsManager.getInstance().removeControl(m_ZengJia_Frame);
					}
				});
			}

			m_ZengJia_Button_gb = new DWButton("取消", m_bgBitmap02);
			m_ZengJia_Button_gb.setDownImage(m_bgBitmap02_ax);
			m_ZengJia_Button_gb.setNearAnchor(m_ZengJia_Frame, Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, -20, -20);
			m_ZengJia_Button_gb.addListener(new DWListener() {

				public void OnDoubleClick()
				{

				}

				public void OnClick()
				{
					DWControlsManager.getInstance().removeControl(m_ZengJia_Frame);
				}
			});

			m_ZengJia_Textbox_TiShi = new DWTextbox("不同的祝福所需要消耗的元宝不同");
			m_ZengJia_Textbox_TiShi.setNearAnchor(m_ZengJia_Title, Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM, 0, 10);

			m_ZengJia_Frame.addControl(m_ZengJia_Background);
			m_ZengJia_Frame.addControl(m_ZengJia_Title);
			m_ZengJia_Frame.addControl(m_ZengJia_ImageBox_gb);
			m_ZengJia_Frame.addControl(m_ZengJia_Textbox_TiShi);
			m_ZengJia_Frame.addControl(m_ZengJia_Button[0]);
			for (int i = 1; i < m_size; i++) {
				m_ZengJia_Frame.addControl(m_ZengJia_Button[i]);
			}
//			m_ZengJia_Frame.addControl(m_ZengJia_Button_gb);
			DWControlsManager.getInstance().addControl(m_ZengJia_Frame);
		}
	};

	public void open(byte index)
	{
		try {
			CopyOnWriteArrayList<Cell> list = new CopyOnWriteArrayList<Cell>();
			DWGameManager.getInstance().getSendMessage().sendBaGuaLu((byte) 1, (byte) 0, 0, list);
			list = null;
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	/** 接收指令后打开界面 */
	public void open_frame()
	{
		updata();
		getGaiLv(0, 0);
		listbox_ZhuangBei();
		huafei_yuanbao();
		bagualu();
		listbox_ZhuangBei();
	}

	public void close(byte index)
	{
		recvAllContorl();
		DWControlsManager.getInstance().removeControl(m_bgFrame);
		DWControlsManager.getInstance().removeControl(m_ZengJia_Frame);
		DWControlsManager.getInstance().removeControl(m_XuanZe_Frame);
	}

	/**
	 * 刷新方法
	 */
	public void recvAllContorl()
	{
		delCacheList();
		m_LianZhi_type = 3;
		m_bgTextbox_ShengCheng.setText(null);
		m_old_yuanbao_num = 0;
		m_JiLv_yuanbao = 0;
		huafei_yuanbao();
		m_bgTextbox_YuanBao.setText(null);
		m_gainlv_quanju = 0;
		m_ZhuangBei_GS_num = 0;
		m_JiLv_num = 0;
		m_JiLv_index = -1;
		m_bgTextbox_TiShi.setShow(false);
		getGaiLvNUM();
		recvGaiLv();
	}

	public void dispose()
	{

	}

	/**
	 * 刷新概率绘制
	 */
	public void recvGaiLv()
	{
		gailv_0 = 0;
		gailv_1 = 0;
		gailv_3 = 0;
		gailv_4 = 0;
		m_ImageBox_num[4].addExternalDraw(new DWExternalDraw() {

			public void externalDraw(DWGraphics g, int x, int y)
			{
				Tools.drawNumber(g, m_bgBitmap_Num, x, y, m_bgBitmap_Num_baifenhao.getWidth(),
						m_bgBitmap_Num_baifenhao.getHeight(), 1, 1, 0, 1, Tools.LEFT_VCENTER, false);
			}
		});
		m_ImageBox_num[3].addExternalDraw(new DWExternalDraw() {

			public void externalDraw(DWGraphics g, int x, int y)
			{
				Tools.drawNumber(g, m_bgBitmap_Num, x, y, m_bgBitmap_Num_baifenhao.getWidth(),
						m_bgBitmap_Num_baifenhao.getHeight(), 1, 1, 0, 1, Tools.LEFT_VCENTER, false);
			}
		});
		m_ImageBox_num[1].addExternalDraw(new DWExternalDraw() {

			public void externalDraw(DWGraphics g, int x, int y)
			{
				Tools.drawNumber(g, m_bgBitmap_Num, x, y, m_bgBitmap_Num_baifenhao.getWidth(),
						m_bgBitmap_Num_baifenhao.getHeight(), 1, 1, 0, 1, Tools.LEFT_VCENTER, false);
			}
		});
		if ((getGaiLv(
				m_ZhuangBei_GS_num * 100 / m_base_num, m_JiLv_num)) / 1000 != 0) {
			m_ImageBox_num[0].setShow(true);
			m_ImageBox_num[0].addExternalDraw(new DWExternalDraw() {

				public void externalDraw(DWGraphics g, int x, int y)
				{
					Tools.drawNumber(g, m_bgBitmap_Num, x, y, m_bgBitmap_Num_baifenhao.getWidth(),
							m_bgBitmap_Num_baifenhao.getHeight(), 1, 1, 0, 1, Tools.LEFT_VCENTER, false);
				}
			});
		}
		else {
			m_ImageBox_num[0].setShow(false);
		}
	}

	public int gailv_0 = 0;
	public int gailv_1 = 0;
	public int gailv_3 = 0;
	public int gailv_4 = 0;

	public void logic()
	{
		if (m_ImageBox_num[5] == null ||
				m_ImageBox_num[4] == null ||
				m_ImageBox_num[3] == null ||
				m_ImageBox_num[2] == null ||
				m_ImageBox_num[1] == null ||
				m_ImageBox_num[0] == null) {
			return;
		}
		m_ImageBox_num[5].setImage(m_bgBitmap_Num_baifenhao);

		if (gailv_4 >= 0) {
			if (getGaiLv(m_ZhuangBei_GS_num * 100 / m_base_num, m_JiLv_num) > 0) {
				m_ImageBox_num[4].addExternalDraw(new DWExternalDraw() {

					public void externalDraw(DWGraphics g, int x, int y)
					{
						Tools.drawNumber(g, m_bgBitmap_Num, x, y, m_bgBitmap_Num_baifenhao.getWidth(),
								m_bgBitmap_Num_baifenhao.getHeight(), 1, 1, gailv_4, 1, Tools.LEFT_VCENTER,
								false);
					}
				});
				gailv_4++;
				if (gailv_4 > ((getGaiLv(m_ZhuangBei_GS_num * 100 / m_base_num, m_JiLv_num)) % 10)) {
					gailv_4 = -1;
					m_ImageBox_num[4].addExternalDraw(new DWExternalDraw() {

						public void externalDraw(DWGraphics g, int x, int y)
						{
							Tools.drawNumber(g, m_bgBitmap_Num, x, y, m_bgBitmap_Num_baifenhao.getWidth(),
									m_bgBitmap_Num_baifenhao.getHeight(), 1, 1, (getGaiLv(m_ZhuangBei_GS_num * 100
											/ m_base_num, m_JiLv_num)) % 10, 1, Tools.LEFT_VCENTER, false);
						}
					});
				}
			}
		}

//		if (gailv_4 == -1) {
		if (gailv_3 >= 0) {
			if (getGaiLv(m_ZhuangBei_GS_num * 100 / m_base_num, m_JiLv_num) > 0) {
				m_ImageBox_num[3].addExternalDraw(new DWExternalDraw() {

					public void externalDraw(DWGraphics g, int x, int y)
					{
						Tools.drawNumber(g, m_bgBitmap_Num, x, y, m_bgBitmap_Num_baifenhao.getWidth(),
								m_bgBitmap_Num_baifenhao
										.getHeight(), 1, 1, gailv_3, 1, Tools.LEFT_VCENTER, false);
					}
				});
				gailv_3++;
				if (gailv_3 > (((getGaiLv(m_ZhuangBei_GS_num * 100 / m_base_num, m_JiLv_num)) % 100) / 10)) {
					gailv_3 = -1;
					m_ImageBox_num[3].addExternalDraw(new DWExternalDraw() {

						public void externalDraw(DWGraphics g, int x, int y)
						{
							Tools.drawNumber(g, m_bgBitmap_Num, x, y, m_bgBitmap_Num_baifenhao.getWidth(),
									m_bgBitmap_Num_baifenhao
											.getHeight(), 1, 1, ((getGaiLv(m_ZhuangBei_GS_num * 100 / m_base_num,
											m_JiLv_num)) % 100) / 10, 1, Tools.LEFT_VCENTER, false);
						}
					});
				}
			}
		}
//		}

		m_ImageBox_num[2].setImage(m_bgBitmap_Num_dian);

//		if (gailv_3 == -1) {
		if (gailv_1 >= 0) {
			if (getGaiLv(m_ZhuangBei_GS_num * 100 / m_base_num, m_JiLv_num) > 0) {
				m_ImageBox_num[1].addExternalDraw(new DWExternalDraw() {

					public void externalDraw(DWGraphics g, int x, int y)
					{
						Tools.drawNumber(g, m_bgBitmap_Num, x, y, m_bgBitmap_Num_baifenhao.getWidth(),
								m_bgBitmap_Num_baifenhao
										.getHeight(), 1, 1, gailv_1, 1, Tools.LEFT_VCENTER, false);
					}
				});
				gailv_1++;
				if (gailv_1 > (((getGaiLv(m_ZhuangBei_GS_num * 100 / m_base_num, m_JiLv_num)) % 1000) / 100)) {
					gailv_1 = -1;
					m_ImageBox_num[1].addExternalDraw(new DWExternalDraw() {

						public void externalDraw(DWGraphics g, int x, int y)
						{
							Tools.drawNumber(g, m_bgBitmap_Num, x, y, m_bgBitmap_Num_baifenhao.getWidth(),
									m_bgBitmap_Num_baifenhao
											.getHeight(), 1, 1, ((getGaiLv(m_ZhuangBei_GS_num * 100 / m_base_num,
											m_JiLv_num)) % 1000) / 100, 1, Tools.LEFT_VCENTER, false);
						}
					});
				}
			}
		}
//		}

//		if (gailv_1 == -1) {
		if (gailv_0 >= 0) {
			if ((getGaiLv(m_ZhuangBei_GS_num * 100 / m_base_num, m_JiLv_num)) / 1000 != 0) {
				m_ImageBox_num[0].setShow(true);
				m_ImageBox_num[0].addExternalDraw(new DWExternalDraw() {

					public void externalDraw(DWGraphics g, int x, int y)
					{
						Tools.drawNumber(g, m_bgBitmap_Num, x, y, m_bgBitmap_Num_baifenhao.getWidth(),
								m_bgBitmap_Num_baifenhao
										.getHeight(), 1, 1, gailv_0, 1, Tools.LEFT_VCENTER, false);
					}
				});
				gailv_0++;
			}
			else {
				m_ImageBox_num[0].setShow(false);
			}
			if (gailv_0 > ((getGaiLv(m_ZhuangBei_GS_num * 100 / m_base_num, m_JiLv_num)) / 1000)) {
				gailv_0 = -1;
				m_ImageBox_num[0].addExternalDraw(new DWExternalDraw() {

					public void externalDraw(DWGraphics g, int x, int y)
					{
						Tools.drawNumber(g, m_bgBitmap_Num, x, y, m_bgBitmap_Num_baifenhao.getWidth(),
								m_bgBitmap_Num_baifenhao
										.getHeight(), 1, 1, (getGaiLv(m_ZhuangBei_GS_num * 100 / m_base_num,
										m_JiLv_num)) / 1000, 1, Tools.LEFT_VCENTER, false);
					}
				});
			}
		}
//		}
	}

	public int m_YuanBao_ZongHe;//增加元宝数总和
	public int m_JiLv_yuanbao;//增加几率消耗元宝
	public int m_JiLv_num;//增加几率

	/** 成功率计算基数 */
	public int m_base_num;
	/** 熔炼指定装备消耗元宝 */
	public int m_yuanbao_num;
	/** 增加成功率选项数量 */
	public byte m_size;

	/** 成功率计算集合 */
	public byte m_size2;

	/** 增加成功率选项集合 */
	public BaGuaLu m_bagualu[] = null;
	/** 成功率计算集合 */
	public BaGuaLu m_gailv[] = null;

	/** 获得的精魂数量 */
	public long m_jinghun_num;
	/** 获得装备的guid */
	public long m_zhuangbei_guid;
	/** 获得碎片的guid */
	public long m_suipian_guid;
	/** 熔炼每级消耗金币数 */
	public int m_jinqian_num;

	/** 最低级别限制 */
	public int m_min_lv;

	public void recvBaGuaLu(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_八卦炉);
		try {
			byte state = dis.readByte();//1:打开界面 2：确定熔炼
			switch (state) {
				case 1:
					int base_num = dis.readInt();//成功率计算基数
					m_base_num = base_num;
					int yuanbao_num = dis.readInt();//熔炼指定装备消耗元宝
					m_yuanbao_num = yuanbao_num;
					int min_lv = dis.readInt();//最低级别限制
					m_min_lv = min_lv;
					byte size = dis.readByte();//增加成功率选项数量
					m_size = size;
					m_bagualu = new BaGuaLu[m_size];
					for (int i = 0; i < m_size; i++) {
						BaGuaLu add_m = new BaGuaLu();
						add_m.setAddchenggong(dis.readInt());//增加成功率
						add_m.setAddchenggongyb(dis.readInt());//消耗元宝
						m_bagualu[i] = add_m;
					}
					int jinqian_num = dis.readInt();//熔炼每级消耗金币
					m_jinqian_num = jinqian_num;
					if (DWGameManager.getInstance().m_role.m_lv >= m_min_lv) {
						open_frame();//打开界面
					}
					else {
						DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "未达到开启等级");
					}
					break;
				case 2:
					byte type = dis.readByte();//0：失败，获得多少精魂 1：获得碎片 2：成功
					delCacheList();
					refreshEquipList();
					m_bgListbox_ZhuangBei.removeAllSubItem();
					listbox_ZhuangBei();
					switch (type) {
						case 0:
							long jinghun_num = dis.readLong();//获得精魂数
							m_jinghun_num = jinghun_num;
							shibai_tishi(m_jinghun_num);
							break;
						case 1:
							DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "游戏币不足");
							break;
						case 2:
							DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "元宝不足");
							break;
						case 3:
							long suipian_guid = dis.readLong();//获得碎片的guid
							m_suipian_guid = suipian_guid;
							Cell cell01 = DWGameManager.getInstance().m_role
									.getCellByGuidForRoleBagColumn(m_suipian_guid);
							suipian_tishi(cell01);
							break;
						case 4:
							long zhuangbei_guid = dis.readLong();//获得装备的guid
							m_zhuangbei_guid = zhuangbei_guid;
							Cell cell02 = DWGameManager.getInstance().m_role
									.getCellByGuidForRoleBagColumn(m_zhuangbei_guid);
							chenggong_tishi(cell02);
							break;
						case 5:
							DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "级别不够");
							break;
					}
					recvAllContorl();
					if (m_equip_list != null) {
						m_bgTextbox_TiShi.setShow(false);
					}
					else {
						m_bgTextbox_TiShi.setShow(true);
					}
					break;
			}
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	/**
	 * 炼化成功提示
	 */
	public DWFrame m_chenggong_Frame = null;
	public DWTitle m_chenggong_Title = null;
	public DWImageBox m_chenggong_guanbi = null;
	public DWGrid m_chenggong_Grid = null;
	public DWTextbox m_chenggong_Textbox = null;
	public DWBackground m_chenggong_Background = null;

	public void chenggong_tishi(final Cell c)
	{
		m_chenggong_Frame = new DWFrame(DWGameManager.Screen_Width / 2, DWGameManager.Screen_Height / 2 + 60);
		m_chenggong_Title = new DWTitle("提示", m_chenggong_Frame);

		m_chenggong_guanbi = new DWImageBox(m_bgBitmap01);
		m_chenggong_guanbi.setNearAnchor(m_chenggong_Title, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER);
		m_chenggong_guanbi.setTouchZoomIn(20, 20);
		m_chenggong_guanbi.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				DWControlsManager.getInstance().removeControl(m_chenggong_Frame);
			}
		});

		m_chenggong_Background = new DWBackground(m_chenggong_Frame.getShowWidth() - 20, m_chenggong_Frame
				.getShowHeight() - 30);
		m_chenggong_Background.setNearAnchor(m_chenggong_Frame, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM, 0, -10);
		m_chenggong_Background.setFill(true);

		m_chenggong_Grid = new DWGrid(m_bgBitmap_Grid);
		m_chenggong_Grid.setNearAnchor(m_chenggong_Frame, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, -100, 0);
		m_chenggong_Grid.m_data = c.m_item;
		m_chenggong_Grid.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				if (m_chenggong_Grid.m_data != null) {
					UIWindows.getInstance().m_bag.showItemMessage(c.m_item);
				}
			}
		});

		m_chenggong_Textbox = new DWTextbox("吉星高照！恭喜您" + DWControlTools.CHANGE_ROW + "获得“" + c.m_item.m_name + "”。");
		m_chenggong_Textbox.setNearAnchor(m_chenggong_Grid, Tools.LEFT_TOP, Tools.RIGHT_TOP, 20, 10);

		m_chenggong_Frame.addControl(m_chenggong_Background);
		m_chenggong_Frame.addControl(m_chenggong_Title);
		m_chenggong_Frame.addControl(m_chenggong_guanbi);
		m_chenggong_Frame.addControl(m_chenggong_Grid);
		m_chenggong_Frame.addControl(m_chenggong_Textbox);
		DWControlsManager.getInstance().addControl(m_chenggong_Frame);
	}

	/**
	 * 炼化碎片提示
	 */
	public DWFrame m_suipian_Frame = null;
	public DWTitle m_suipian_Title = null;
	public DWImageBox m_suipian_guanbi = null;
	public DWGrid m_suipian_Grid = null;
	public DWTextbox m_suipian_Textbox = null;
	public DWBackground m_suipian_Background = null;

	public void suipian_tishi(final Cell c)
	{
		m_suipian_Frame = new DWFrame(DWGameManager.Screen_Width / 2, DWGameManager.Screen_Height / 2 + 60);
		m_suipian_Title = new DWTitle("提示", m_suipian_Frame);

		m_suipian_guanbi = new DWImageBox(m_bgBitmap01);
		m_suipian_guanbi.setNearAnchor(m_suipian_Title, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER);
		m_suipian_guanbi.setTouchZoomIn(20, 20);
		m_suipian_guanbi.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				DWControlsManager.getInstance().removeControl(m_suipian_Frame);
			}
		});

		m_suipian_Background = new DWBackground(m_suipian_Frame.getShowWidth() - 20, m_suipian_Frame
				.getShowHeight() - 30);
		m_suipian_Background.setNearAnchor(m_suipian_Frame, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM, 0, -10);
		m_suipian_Background.setFill(true);

		m_suipian_Grid = new DWGrid(m_bgBitmap_Grid);
		m_suipian_Grid.setNearAnchor(m_suipian_Frame, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, -100, 0);
		m_suipian_Grid.m_data = c.m_item;
		m_suipian_Grid.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				if (m_suipian_Grid.m_data != null) {
					UIWindows.getInstance().m_bag.showItemMessage(c.m_item);
				}
			}
		});

		m_suipian_Textbox = new DWTextbox("吉星高照！恭喜您" + DWControlTools.CHANGE_ROW + "获得“" + c.m_item.m_name + "”。");
		m_suipian_Textbox.setNearAnchor(m_suipian_Grid, Tools.LEFT_TOP, Tools.RIGHT_TOP, 20, 10);

		m_suipian_Frame.addControl(m_suipian_Background);
		m_suipian_Frame.addControl(m_suipian_Title);
		m_suipian_Frame.addControl(m_suipian_guanbi);
		m_suipian_Frame.addControl(m_suipian_Grid);
		m_suipian_Frame.addControl(m_suipian_Textbox);
		DWControlsManager.getInstance().addControl(m_suipian_Frame);
	}

	/**
	 * 炼化失败提示
	 */
	public DWFrame m_shibaiFrame = null;
	public DWTitle m_shibaiTitle = null;
	public DWImageBox m_shibai_guanbi = null;
	public DWTextbox m_shibai_Textbox = null;
	public DWBackground m_shibai_Background = null;

	public void shibai_tishi(long jinghun_num)
	{
		m_shibaiFrame = new DWFrame(DWGameManager.Screen_Width / 2, DWGameManager.Screen_Height / 2 + 60);
		m_shibaiTitle = new DWTitle("提示", m_shibaiFrame);

		m_shibai_guanbi = new DWImageBox(m_bgBitmap01);
		m_shibai_guanbi.setNearAnchor(m_shibaiTitle, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER);
		m_shibai_guanbi.setTouchZoomIn(20, 20);
		m_shibai_guanbi.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				DWControlsManager.getInstance().removeControl(m_shibaiFrame);
			}
		});

		m_shibai_Background = new DWBackground(m_shibaiFrame.getShowWidth() - 20, m_shibaiFrame.getShowHeight() - 30);
		m_shibai_Background.setNearAnchor(m_shibaiFrame, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM, 0, -10);
		m_shibai_Background.setFill(true);

		m_shibai_Textbox = new DWTextbox("很遗憾！炼化失败您获得精魂" + jinghun_num);
		m_shibai_Textbox.setNearAnchor(m_shibaiFrame, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);

		m_shibaiFrame.addControl(m_shibai_Background);
		m_shibaiFrame.addControl(m_shibaiTitle);
		m_shibaiFrame.addControl(m_shibai_guanbi);
		m_shibaiFrame.addControl(m_shibai_Textbox);
		DWControlsManager.getInstance().addControl(m_shibaiFrame);
	}
}
